#include <kernel/vfs.h>
#include <kernel/syslog.h>
#include <kernel/kobject.h>


static LIST_HEAD(fs_list_head);
static struct vfs_file vfs_file_fd[VFS_MAX_FD];


struct file_system_type* find_fs_by_name(const char *name)
{
	if(!name)
		return NULL;

    struct file_system_type *fs_node;
    struct list_node *head = &fs_list_head;

    list_for_each_entry(fs_node, head, struct file_system_type, link) {
        if(strcmp(fs_node->name, name) == 0) {
            return fs_node;
        }
    }

	return NULL;
}


bool filesystem_register(struct file_system_type *fs)
{
    if(fs == NULL || fs->name == NULL) {
        VFS_SYSLOG_ERROR("fs is NULL or name of fs is not set");
        return false;
    }

    if(find_fs_by_name(fs->name)) {
        VFS_SYSLOG_ERROR("%s fs is registered", fs->name);
        return false;
    }

    list_add_node_at_tail(&fs_list_head, &fs->link);
}


bool filesystem_unregister(struct file_system_type *fs)
{
    if(fs == NULL || fs->name == NULL) {
        VFS_SYSLOG_ERROR("fs is NULL or name of fs is not set");
        return false;
    }

    if(find_fs_by_name(fs->name) == NULL) {
        VFS_SYSLOG_ERROR("%s fs is not register", fs->name);
        return false;
    }

    list_del_node(&fs->link);

    return true;
}


void vfs_do_init(void)
{

}


int vfs_mount(const char *dev, const char *path, const char *fsname)
{
     
}


int vfs_umount(const char *path)
{
    
}


int vfs_open(const char *path, int flags)
{
    
}

int vfs_close(int fd)
{

}

int vfs_read(int32_t fd, void *buf, uint32_t nbytes)
{

}

int vfs_write(int32_t fd, void *buf, uint32_t nbytes)
{

}


int vfs_ioctl(int32_t fd, int32_t cmd, uint32_t arg)
{

}

int vfs_lseek(int32_t fd, int32_t offset, int32_t whence)
{

}


int vfs_mkdir(const char *path)
{

}


int vfs_rmdir(const char *path)
{

}


int vfs_chdir(const char *path)
{

}

int vfs_stat(const char *path, struct vfs_stat *buf)
{

}


int vfs_access(const char *path, int32_t amode)
{

}
